package com.moyu.user.domain.user;

import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.moyu.user.domain.dept.Dept;
import com.moyu.user.domain.role.Role;
import jakarta.validation.Valid;
import jakarta.validation.constraints.*;
import jakarta.validation.groups.ConvertGroup;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 用户实体类
 *
 * @Author 赵彦博
 * @Date 2024/11/19 10:57
 */
@Data
@ToString
@EqualsAndHashCode
@TableName("tb_user")
public class User {

    /**
     * 用户ID
     */
    @JsonSerialize(using = ToStringSerializer.class)
    @TableId(type = IdType.ASSIGN_ID)
    private Long id;

    /**
     * 用户名
     */
    @NotBlank(message = "⽤⼾名不能为空")
    private String username;

    /**
     * 密码
     */
    @NotBlank(message = "⽤⼾密码不能为空")
    @Size(min = 5, max = 10, message = "密码⻓度不能少于6位，不能⼤于10位")
    private String password;

    /**
     * 姓名
     */
    @NotBlank(message = "真名不能为空")
    private String fullName;

    /**
     * 性别
     */
    private String gender;

    /**
     * 部门ID
     */
    private Long deptId;

    private Dept dept;

    /**
     * 邮箱地址
     */
    @Email(message = "必须符合邮箱格式")
    private String emailAddress;

    /**
     * 手机号码
     */
    @Pattern(regexp = "^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}$", message = "⼿机号码格式不正确")
    private String phoneNumber;

    /**
     * 头像链接
     */
    private String profilePicture;

    /**
     * /**
     * 角色
     */
    @TableField(typeHandler = JacksonTypeHandler.class, exist = false)
    private List<Role> roles;

    @TableField(fill = FieldFill.INSERT)
    private Long createBy;

    @TableField(fill = FieldFill.INSERT)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime createTime;

    @TableField(fill = FieldFill.UPDATE)
    private Long updateBy;

    @TableField(fill = FieldFill.UPDATE)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime updateTime;
}
